/* Copyright 2010 John L. Reilly

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

package com.riq;

import java.util.Collection;

import com.riq.entity.HasPrimaryKey;

/**
 * Interface that sits in front of the data storage layer.
 *
 * @author Steven Hakusa (shakusa@google.com)
 */

public interface DataStore { 

  /**
   * Returns the given entity by its primary key
   * @param clazz type of object to return
   * @param key the key
   * @return the alert, or null if no alert exists with that key
   */
  <T> T getByKey(Class<T> clazz, Object key);
  
  /**
   * Deletes the given entity by its primary key
   * @param clazz type of object to return
   * @param key the key
   * @return the alert, or null if no alert exists with that key
   */
  <T> T deleteByKey(Object key);

  /**
   * Persists the given entity to the datastore. If an alert with the same key
   * already exists, it will be overwritten.
   *
   * @param object the alert to persist
   */
  <T extends HasPrimaryKey> void makePersistent(T object);


  /**
   * Persists the given alerts to the datastore. This is more efficient than
   * calling persisting each alert individually. If any alerts with the same
   * key already exist, they will be overwritten.
   *
   * @param alerts the alerts to persist
   */
  <T extends HasPrimaryKey> void makePersistAll(Collection<T> objs);

void clearCache();



}

